﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract TinTucTieuDiem typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class TinTucTieuDiemDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<TinTucTieuDiemDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.TinTucTieuDiem _currentTinTucTieuDiem = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxTinTucTieuDiemDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxTinTucTieuDiemErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxTinTucTieuDiemBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDTinTucDanhMuc property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDTinTucDanhMucDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDTinTuc property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDTinTucDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.TinTuc> _IDTinTucList;
		
		/// <summary> 
		/// The list of selectable TinTuc
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.TinTuc> IDTinTucList
		{
			get {return this._IDTinTucList;}
			set 
			{
				this._IDTinTucList = value;
				this.uxIDTinTucDataGridViewColumn.DataSource = null;
				this.uxIDTinTucDataGridViewColumn.DataSource = this._IDTinTucList;
			}
		}
		
		private bool _allowNewItemInIDTinTucList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of TinTuc
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDTinTucList
		{
			get { return _allowNewItemInIDTinTucList;}
			set
			{
				this._allowNewItemInIDTinTucList = value;
				this.uxIDTinTucDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.TinTucDanhMuc> _IDTinTucDanhMucList;
		
		/// <summary> 
		/// The list of selectable TinTucDanhMuc
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.TinTucDanhMuc> IDTinTucDanhMucList
		{
			get {return this._IDTinTucDanhMucList;}
			set 
			{
				this._IDTinTucDanhMucList = value;
				this.uxIDTinTucDanhMucDataGridViewColumn.DataSource = null;
				this.uxIDTinTucDanhMucDataGridViewColumn.DataSource = this._IDTinTucDanhMucList;
			}
		}
		
		private bool _allowNewItemInIDTinTucDanhMucList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of TinTucDanhMuc
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDTinTucDanhMucList
		{
			get { return _allowNewItemInIDTinTucDanhMucList;}
			set
			{
				this._allowNewItemInIDTinTucDanhMucList = value;
				this.uxIDTinTucDanhMucDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.TinTucTieuDiem> _TinTucTieuDiemList;
				
		/// <summary> 
		/// The list of TinTucTieuDiem to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.TinTucTieuDiem> TinTucTieuDiemList
		{
			get {return this._TinTucTieuDiemList;}
			set
			{
				this._TinTucTieuDiemList = value;
				this.uxTinTucTieuDiemBindingSource.DataSource = null;
				this.uxTinTucTieuDiemBindingSource.DataSource = value;
				this.uxTinTucTieuDiemDataGridView.DataSource = null;
				this.uxTinTucTieuDiemDataGridView.DataSource = this.uxTinTucTieuDiemBindingSource;				
				//this.uxTinTucTieuDiemBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxTinTucTieuDiemBindingSource_ListChanged);
				this.uxTinTucTieuDiemBindingSource.CurrentItemChanged += new System.EventHandler(OnTinTucTieuDiemBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnTinTucTieuDiemBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentTinTucTieuDiem = uxTinTucTieuDiemBindingSource.Current as Entities.TinTucTieuDiem;
			
			if (_currentTinTucTieuDiem != null)
			{
				_currentTinTucTieuDiem.Validate();
			}
			//_TinTucTieuDiem.Validate();
			OnCurrentEntityChanged();
		}

		//void uxTinTucTieuDiemBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.TinTucTieuDiem"/> instance.
		/// </summary>
		public Entities.TinTucTieuDiem SelectedTinTucTieuDiem
		{
			get {return this._currentTinTucTieuDiem;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxTinTucTieuDiemDataGridView.VirtualMode;}
			set
			{
				this.uxTinTucTieuDiemDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxTinTucTieuDiemDataGridView.AllowUserToAddRows;}
			set {this.uxTinTucTieuDiemDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxTinTucTieuDiemDataGridView.AllowUserToDeleteRows;}
			set {this.uxTinTucTieuDiemDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxTinTucTieuDiemDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxTinTucTieuDiemDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="TinTucTieuDiemDataGridViewBase"/> class.
		/// </summary>
		public TinTucTieuDiemDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxTinTucTieuDiemDataGridView = new System.Windows.Forms.DataGridView();
			this.uxTinTucTieuDiemBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxTinTucTieuDiemErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDTinTucDanhMucDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDTinTucDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDTinTucBindingSource = new TinTucBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucBindingSource)).BeginInit();
			//this.uxIDTinTucDanhMucBindingSource = new TinTucDanhMucBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucDanhMucBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxTinTucTieuDiemErrorProvider
			// 
			this.uxTinTucTieuDiemErrorProvider.ContainerControl = this;
			this.uxTinTucTieuDiemErrorProvider.DataSource = this.uxTinTucTieuDiemBindingSource;						
			// 
			// uxTinTucTieuDiemDataGridView
			// 
			this.uxTinTucTieuDiemDataGridView.AutoGenerateColumns = false;
			this.uxTinTucTieuDiemDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxTinTucTieuDiemDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDTinTucDanhMucDataGridViewColumn,
		this.uxIDTinTucDataGridViewColumn			});
			this.uxTinTucTieuDiemDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxTinTucTieuDiemDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxTinTucTieuDiemDataGridView.Name = "uxTinTucTieuDiemDataGridView";
			this.uxTinTucTieuDiemDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxTinTucTieuDiemDataGridView.TabIndex = 0;	
			this.uxTinTucTieuDiemDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxTinTucTieuDiemDataGridView.EnableHeadersVisualStyles = false;
			this.uxTinTucTieuDiemDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnTinTucTieuDiemDataGridViewDataError);
			this.uxTinTucTieuDiemDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucTieuDiemDataGridViewCellValueNeeded);
			this.uxTinTucTieuDiemDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucTieuDiemDataGridViewCellValuePushed);
			
			//
			// uxIDTinTucDanhMucDataGridViewColumn
			//
			this.uxIDTinTucDanhMucDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDTinTucDanhMucDataGridViewColumn.DataPropertyName = "IDTinTucDanhMuc";
			this.uxIDTinTucDanhMucDataGridViewColumn.HeaderText = "IDTinTucDanhMuc";
			this.uxIDTinTucDanhMucDataGridViewColumn.Name = "uxIDTinTucDanhMucDataGridViewColumn";
			this.uxIDTinTucDanhMucDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDTinTucDanhMucDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDTinTucDanhMucDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDTinTucDataGridViewColumn
			//
			this.uxIDTinTucDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDTinTucDataGridViewColumn.DataPropertyName = "IDTinTuc";
			this.uxIDTinTucDataGridViewColumn.HeaderText = "IDTinTuc";
			this.uxIDTinTucDataGridViewColumn.Name = "uxIDTinTucDataGridViewColumn";
			this.uxIDTinTucDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDTinTucDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDTinTucDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDTinTucDataGridViewColumn
			//				
			this.uxIDTinTucDataGridViewColumn.DisplayMember = "IDTinTucDanhMuc";	
			this.uxIDTinTucDataGridViewColumn.ValueMember = "IDTinTuc";	
			this.uxIDTinTucDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDTinTucDataGridViewColumn.DataSource = uxIDTinTucBindingSource;				
				
			//
			// uxIDTinTucDanhMucDataGridViewColumn
			//				
			this.uxIDTinTucDanhMucDataGridViewColumn.DisplayMember = "IDTinTucDanhMucCha";	
			this.uxIDTinTucDanhMucDataGridViewColumn.ValueMember = "IDTinTucDanhMuc";	
			this.uxIDTinTucDanhMucDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDTinTucDanhMucDataGridViewColumn.DataSource = uxIDTinTucDanhMucBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxTinTucTieuDiemDataGridView);
			this.Name = "TinTucTieuDiemDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucDanhMucBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucTieuDiemBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				TinTucTieuDiemDataGridViewEventArgs args = new TinTucTieuDiemDataGridViewEventArgs();
				args.TinTucTieuDiem = _currentTinTucTieuDiem;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class TinTucTieuDiemDataGridViewEventArgs : System.EventArgs
		{
			private Entities.TinTucTieuDiem	_TinTucTieuDiem;
	
			/// <summary>
			/// the  Entities.TinTucTieuDiem instance.
			/// </summary>
			public Entities.TinTucTieuDiem TinTucTieuDiem
			{
				get { return _TinTucTieuDiem; }
				set { _TinTucTieuDiem = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxTinTucTieuDiemDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucTieuDiemDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxTinTucTieuDiemDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucTieuDiemDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucTieuDiemDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucDanhMucDataGridViewColumn":
						e.Value = TinTucTieuDiemList[e.RowIndex].IDTinTucDanhMuc;
						break;
					case "uxIDTinTucDataGridViewColumn":
						e.Value = TinTucTieuDiemList[e.RowIndex].IDTinTuc;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxTinTucTieuDiemDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucTieuDiemDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucTieuDiemDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucDanhMucDataGridViewColumn":
						TinTucTieuDiemList[e.RowIndex].IDTinTucDanhMuc = (System.Guid)e.Value;
						break;
					case "uxIDTinTucDataGridViewColumn":
						TinTucTieuDiemList[e.RowIndex].IDTinTuc = (System.Guid)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
